/**
 * update: 2018-11-28
 * author: xuek
 * explain: 查询结果 转换理想格式
 */

// 指定字段换换格式 ( 通用 )
export const dataType = data => {
  let arr = [];
  for (let i in data) {
    let str = "";
    let val = data[i];
    switch (i) {
      case "name":
        str = "姓名：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "idCard":
        str = "身份证：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "mobile":
        str = "手机号：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "accountNo":
        str = "银行卡号：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "resShow":
        str = "查询结果：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "company":
        str = "公司名称：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "area":
        str = "所在城市：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "position":
        str = "岗位名称：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "salary":
        str = "薪酬水平：";
        arr.push({
          lab: str,
          val: val[0] + "（月薪）",
          valueHighLight: val[1]
        });
        break;
      case "sex":
        str = "性别：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "birth":
        str = "生日：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "marryState":
        str = "婚姻状况：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "workYear":
        str = "工作年限：";
        switch (data[i]) {
          case null:
            val = "";
            break;
          case "12":
            val = "10年及以上";
            break;
          default:
            val = data[i] + "年";
            break;
        }
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "address":
        str = "地址：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "前科比对结果":
        str = "前科比对结果：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "涉毒比对结果":
        str = "涉毒比对结果：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "在逃比对结果":
        str = "在逃比对结果：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "吸毒比对结果":
        str = "吸毒比对结果：";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "time":
        str = "最近案发距今：";
        arr.push({
          lab: str,
          val: val
        });
        break;
    }
  }
  return arr;
};

// 删除对象中指定属性 ( 薪酬查询... )
export const delObjAttr = (data, arr) => {
  for (let i in data) {
    for (let x in arr) {
      delete data[arr[x]];
    }
  }
  return data;
};

// 有序追加
async function orderPush(data, str) {
  for (let i in data) {
    if (data[i].title == str) {
      return data[i];
    }
  }
}

// 返回结果是否为有效结果 ( 人群画像... )
export const isValidData = data => {
  let arr = [];
  let orderStr = ["籍贯地", "性别", "生日", "婚姻", "开始工作时间", "就业年限", "当前地区", "当前薪资", "当前行业", "最后工作单位", "最后工作岗位", "最近第二份工作单位", "最近第二份工作岗位", "学历", "最后毕业学校", "专业", "最后教育开始时间", "最后教育结束时间"];

  const arrPush = res => {
    arr.push({
      lab: res.title + "：",
      val: res.text,
      isValid: res.scoreAHit
    });
  };

  orderPush(data, orderStr[0]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[1]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[2]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[3]).then(res => {res.title = "婚姻状况";arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[4]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[5]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[6]).then(res => {res.title = "当前工作地";arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[7]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[8]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[9]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[10]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[11]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[12]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[13]).then(res => {res.title = "最高学历";arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[14]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[15]).then(res => {res.title = "最后专业";arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[16]).then(res => {arrPush(res);}).catch(res => {});
  orderPush(data, orderStr[17]).then(res => {arrPush(res);}).catch(res => {});

  return arr;
};

const moneyRange = val => {
  let res;
  switch (val) {
    case "极高":
      res = "100000+";
      break;
    case "较高":
      res = "30000-100000";
      break;
    case "高":
      res = "10000-30000";
      break;
    case "中":
      res = "5000-10000";
      break;
    case "低":
      res = "3000-5000";
      break;
    case "较低":
      res = "500-3000";
      break;
    case "极低":
      res = "1-500";
      break;
    case "无":
      res = "0";
      break;
  }
  return res;
};
const frequencyRange = val => {
  let res;
  switch (val) {
    case "极高":
      res = "100+";
      break;
    case "较高":
      res = "50-100";
      break;
    case "高":
      res = "20-50";
      break;
    case "中":
      res = "10-20";
      break;
    case "低":
      res = "5-10";
      break;
    case "较低":
      res = "3-5";
      break;
    case "极低":
      res = "1-3";
      break;
    case "无":
      res = "0";
      break;
  }
  return res;
};
const daysRange = val => {
  let res;
  switch (val) {
    case "M6":
      res = "180+";
      break;
    case "M3":
      res = "90-180";
      break;
    case "M2":
      res = "60-90";
      break;
    case "M1":
      res = "30-60";
      break;
    case "W2":
      res = "15-30";
      break;
    case "W1":
      res = "7-15";
      break;
    case "D3":
      res = "3-7";
      break;
    case "D1":
      res = "0-2";
      break;
    case "无":
      res = "0";
      break;
  }
  return res;
};
// 借贷宝(jdb) 数据格式
const jdbDataType = data => {
  let arr = [];
  for (let i in data) {
    let str = "";
    let val = data[i];
    switch (i) {
      case "is_high_risk_user":
        str = "是否高风险用户";
        switch (data[i]) {
          case 1:
          case "1":
            val = "高风险用户";
            break;
          case "无":
            val = "非高风险用户";
            break;
        }
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "last_visit_dt":
        str = "最近一次访问日期";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "30d_overdue_cnt":
        str = "30天以上逾期次数";
        arr.push({
          lab: str,
          val: frequencyRange(val)
        });
        break;
      case "his_overdue_amt":
        str = "历史逾期金额";
        arr.push({
          lab: str,
          val: moneyRange(val)
        });
        break;
      case "last_overdue_dt":
        str = "最近一次逾期时间";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "last_overdue_amt":
        str = "最近一次逾期金额";
        arr.push({
          lab: str,
          val: moneyRange(val)
        });
        break;
      case "curr_overdue_amt":
        str = "当前逾期金额";
        arr.push({
          lab: str,
          val: moneyRange(val)
        });
        break;
      case "curr_overdue_days":
        str = "当前逾期最大天数";
        arr.push({
          lab: str,
          val: daysRange(val)
        });
        break;
      case "first_overdue_dt":
        str = "首次逾期时间";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "first_overdue_amt":
        str = "首次逾期金额";
        arr.push({
          lab: str,
          val: moneyRange(val)
        });
        break;
      case "last_repay_tm":
        str = "最近一次还款时间";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "repay_times":
        str = "总还款次数";
        arr.push({
          lab: str,
          val: frequencyRange(val)
        });
        break;
      case "curr_debt_product_cnt":
        str = "正在进行的贷款笔数";
        arr.push({
          lab: str,
          val: frequencyRange(val)
        });
        break;
      case "total_in_order_cnt":
        str = "历史贷款笔数";
        arr.push({
          lab: str,
          val: frequencyRange(val)
        });
        break;
      case "total_in_order_amt":
        str = "历史总借款金额";
        arr.push({
          lab: str,
          val: moneyRange(val)
        });
        break;
    }
  }
  return arr;
};
// 无忧借条(wu) 数据格式
const wuDataType = data => {
  let arr = [];
  for (let i = 0; i < data.length; i++) {
    if (data[i].indexOf("：") !== -1) {
      arr.push({
        lab: data[i].split("：")[0],
        val: data[i].split("：")[1].split("。")[0]
      });
    } else {
      arr.push({
        lab: "查询结果",
        val: data[i]
      });
    }
  }
  return arr;
};
// 今借到(jjd) 数据格式
const jjdDataType = data => {
  let arr = [];
  for (let i in data) {
    let str = "";
    let val = data[i];
    switch (i) {
      case "register_time":
        str = "注册日期";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_borrow_people_num":
        str = "累积借入人数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_lend_cnt":
        str = "累积借出次数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_borrow_amt":
        str = "累积借款金额(元)";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_current_overdue_amt":
        str = "当前逾期金额(元)";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overdue_7days_cnt":
        str = ">=7天逾期次数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_current_overdue_cnt":
        str = "当前逾期笔数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overdue_7days_amt":
        str = ">=7天逾期金额(元)";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overdue_amt":
        str = "累积逾期总额(元)";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overdue_cnt":
        str = "历史逾期次数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_to_overdue_max_amt":
        str = "最大逾期金额(元)";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_current_overdue_7days_cnt":
        str = "最近7天逾期次数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overude_90_days":
        str = "是否超过90天的逾期";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_borrow_cnt":
        str = "累积借入笔数";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overdue_30days_amt":
        str = ">=30天逾期金额(元)";
        arr.push({
          lab: str,
          val: val
        });
        break;
      case "n_overdue_30days_cnt":
        str = ">=30天逾期次数";
        arr.push({
          lab: str,
          val: val
        });
        break;
    }
  }
  return arr;
};

// 四大借条数据格式
export const fourIOUDataType = val => {
  let res = {
    resShow: "",
    nET_LOAN_BLACK_LIST: {
      hit: null
    },
    jIE_DAI_BAO_LOAN: {
      hit: null,
      list: []
    },
    wU_YOU_LOAN: {
      hit: null,
      list: []
    },
    jIN_JIE_DAO_LOAN: {
      hit: null,
      list: [],
      tableData: []
    },
    mI_FANG_LOAN: {
      hit: null,
      tableData: []
    }
  };

  res.resShow = val.resShow;

  if (val.queryInfoTO.nET_LOAN_BLACK_LIST !== null) {
    res.nET_LOAN_BLACK_LIST.hit = val.queryInfoTO.nET_LOAN_BLACK_LIST.hit;
  } else {
    res.nET_LOAN_BLACK_LIST = val.queryInfoTO.nET_LOAN_BLACK_LIST;
  }

  if (val.queryInfoTO.jIE_DAI_BAO_LOAN !== null) {
    res.jIE_DAI_BAO_LOAN.hit = val.queryInfoTO.jIE_DAI_BAO_LOAN.hit;
    res.jIE_DAI_BAO_LOAN.list = jdbDataType(val.queryInfoTO.jIE_DAI_BAO_LOAN);
  }

  if (val.queryInfoTO.wU_YOU_LOAN !== null) {
    res.wU_YOU_LOAN.hit = val.queryInfoTO.wU_YOU_LOAN.hit;
    if (val.queryInfoTO.wU_YOU_LOAN.datalist[0].result.indexOf("，") !== -1) {
      res.wU_YOU_LOAN.list = wuDataType(val.queryInfoTO.wU_YOU_LOAN.datalist[0].result.split("，"));
    } else {
      res.wU_YOU_LOAN.list = [val.queryInfoTO.wU_YOU_LOAN.datalist[0].result];
    }
  }

  if (val.queryInfoTO.jIN_JIE_DAO_LOAN !== null) {
    res.jIN_JIE_DAO_LOAN.hit = val.queryInfoTO.jIN_JIE_DAO_LOAN.hit;
    res.jIN_JIE_DAO_LOAN.list = jjdDataType(val.queryInfoTO.jIN_JIE_DAO_LOAN);
    res.jIN_JIE_DAO_LOAN.tableData = val.queryInfoTO.jIN_JIE_DAO_LOAN.overduelist;
  }

  if (val.queryInfoTO.mI_FANG_LOAN !== null) {
    res.mI_FANG_LOAN.hit = val.queryInfoTO.mI_FANG_LOAN.hit;
    res.mI_FANG_LOAN.tableData = val.queryInfoTO.mI_FANG_LOAN.data.data_list;
  }

  return res;
};
